package com.lxyk.controller.monthly;

import com.github.pagehelper.PageInfo;
import com.lxyk.domain.Job;
import com.lxyk.service.monthly.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @ClassName JobDaoController
 * @Description TODO
 * @Author FJQ
 * @Date 2022/4/10 18:40
 * @Version 1.0
 **/
//学生就业
@Controller
@RequestMapping("/job")
public class JobDaoController {

    @Autowired
    private JobService jobService;


    @RequestMapping("/employment")
    public String monthlyTest(Integer id,String name,String className,Model model,Integer pageNum,Integer pageSize){
        if (pageNum == null || "".equals(pageNum) || pageNum <=0) {
            pageNum = 1;
        }
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = 10;
        }
        Map map = new HashMap();
        map.put("id",id);
        map.put("name",name);
        map.put("className",className);
        PageInfo<Job> pageInfo = jobService.QueryAll(map,pageNum, pageSize);
        System.out.println(pageInfo);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("name",name);
        model.addAttribute("className",className);
        model.addAttribute("id",id);
        return "student-employment";
    }


    //新增
    @RequestMapping("/jobInsert")
    public String insert(Job job){
        int saveJob = jobService.saveJob(job);
        if (saveJob > 0){
            System.out.println("新增成功！");
        }else {
            System.out.println("新增失败！");
        }
        return "redirect:/job/employment";
    }

    //删除
    @RequestMapping("/remove")
    public String delete(HttpServletRequest request, Integer id){
        boolean bool = jobService.removeJobById(id);
        if(bool){
            request.getSession().setAttribute("msg", "删除成功!");
        }else{
            request.getSession().setAttribute("msg", "删除失败!");
        }
        return "redirect:/job/employment";
    }

    //根据id查询
    @RequestMapping("/jobById")
    public String findById(Model model,Integer id){
        Job job = jobService.QueryById(id);
        model.addAttribute("job",job);
        return "student-employment-update";
    }

    //更新
    @RequestMapping("/jobUpdate")
    public String update(HttpServletRequest request, Job job){
        System.out.println(job+"---------------------------------");
        boolean bool = jobService.modifyJob(job);

        if(bool){
            request.getSession().setAttribute("msg", "修改成功!");
        }else{
            request.getSession().setAttribute("msg", "修改失败!");
        }
        return "redirect:/job/employment";
    }
}
